package com.kunteng.ynhxksh.service;

/**
 * Created By ShiYun with IntelliJ IDEA on 2018/4/2 10:48
 *
 * @author: ShiYun
 * @Email: 515867726@qq.com
 * @Date: 2018/4/2
 * To change this template use File | Settings | File Templates.
 */

import com.kunteng.ynhxksh.dao.SHGKDao;
import com.kunteng.ynhxksh.mapper.D_T_DZFP_FPJYXXMapper;
import com.kunteng.ynhxksh.mapper.T_COMPANY_INFORMATIONMapper;
import com.kunteng.ynhxksh.mapper.T_POS_JYXXMapper;
import com.kunteng.ynhxksh.mapper.T_POS_MANAGEMapper;
import com.kunteng.ynhxksh.util.DateUtil;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 商户管控服务
 */
@Service
public class SHGKService implements SHGKDao {

    Logger logger = LoggerFactory.getLogger(SHGKService.class);

    @Autowired
    private T_COMPANY_INFORMATIONMapper t_company_informationMapper;
    @Autowired
    private T_POS_JYXXMapper t_pos_jyxxMapper;
    @Autowired
    private D_T_DZFP_FPJYXXMapper d_t_dzfp_fpjyxxMapper;
    @Autowired
    private T_POS_MANAGEMapper t_pos_manageMapper;

    @Override
    public JSONObject shopStatisticalNum(String date) {
        logger.info("shopStatisticalNum {}", date);
        JSONObject object = new JSONObject();
        object.put("SHZS", t_company_informationMapper.fingByShopNum());
        object.put("YRWSHS", t_company_informationMapper.fingByShopAndPosNum());
        object.put("JRJYSHS", t_pos_jyxxMapper.findByDrjyShopnum(date));
        object.put("JRKPSHS", d_t_dzfp_fpjyxxMapper.findByDrkpShopnum(date));
        return object;
    }

    @Override
    public JSONObject newShopWeekNum(String date) {
        logger.info("newShopWeekNum {}", date);
        JSONObject object = new JSONObject();
        for (int i = 0; i < 7; i++) {
            String dateto = DateUtil.getDay(date, -i);
            object.put(dateto, t_pos_manageMapper.findByDateXRWSH(dateto));
        }
        return object;
    }

    @Override
    public JSONObject shopJyzeQJ(String date) {
        logger.info("shopJyzeQJ {}", date);
        JSONObject object = new JSONObject();
        List<Map> list = t_pos_jyxxMapper.findByDateJYJES(date);
        int jyeOne = t_company_informationMapper.fingByShopNum() - t_pos_jyxxMapper.findByDrjyShopnum(date);
        int jyeTwo = 0;
        int jyeThree = 0;
        int jyeFour = 0;
        int jyeFive = 0;
        int jyeSix = 0;
        for (Map map : list) {
            double jyes = Double.parseDouble(map.get("jyjes").toString());
            if (jyes < 2000) {
                jyeOne++;
            } else if (jyes >= 2000 & jyes < 5000) {
                jyeTwo++;
            } else if (jyes >= 5000 & jyes < 10000) {
                jyeThree++;
            } else if (jyes >= 10000 & jyes < 50000) {
                jyeFour++;
            } else if (jyes >= 50000 & jyes <= 100000) {
                jyeFive++;
            } else if (jyes > 100000) {
                jyeSix++;
            }
        }
        object.put("jyeOne", jyeOne);
        object.put("jyeTwo", jyeTwo);
        object.put("jyeThree", jyeThree);
        object.put("jyeFour", jyeFour);
        object.put("jyeFive", jyeFive);
        object.put("jyeSix", jyeSix);
        return object;
    }

    @Override
    public JSONObject shopJYNumWeek(String date) {
        logger.info("shopJYNumWeek {}", date);
        JSONObject object = new JSONObject();
        for (int i = 0; i < 7; i++) {
            String dateto = DateUtil.getDay(date, -i);
            object.put(dateto, t_pos_jyxxMapper.findByDrjyShopnum(dateto));
        }
        return object;
    }
}
